<?php
	function f410($sql){
		//data handle instance
		//set request
		//define format
		//set format
		//define query string
		//process time
		//process fitler
		$dataHandle = new DataHandle();
		$dataHandle->setRequest("410");



		$dataType = getValue($_GET['dataType']);
		$action = getValue($_GET['action']);

		if ($dataType == "json"){
			$format = array(
				"StartTime" => "dateY-m-d H:i:s",
				"EndTime" => "dateY-m-d H:i:s",
			);
			$dataHandle->setFormat($format);
			$error = $dataHandle->processTime($startTime, $endTime);
			if($error == ""){
				$filter = $dataHandle->processFilters($startTime, $endTime, "mix_produced_activities_view","Start_Time");
				$query = getQuery($startTime, $endTime, $filter);
				print($dataHandle->printJSON($sql, $query));
			}
			else
				print($error);
		}
		else if($action == "getYears"){
			$query = getYears();
			print($dataHandle->printJSON($sql, $query));
		}
		else{
			$temp = array();
			$temp['error'] = "410: Bad request";
			print(json_encode($temp));
		}

		unset($dataHandle);

	}

	function getQuery(&$startTime, &$endTime, &$filter){
		$queryString = "
			SELECT
				name AS 'Line',
				product_id AS 'Recipe#',
				Start_Time AS 'StartTime',
				End_Time AS 'EndTime',
				description AS 'Description'
			FROM mix_produced_activities_view ";

		$queryString = $queryString.$filter;

		$queryString = $queryString."order by Start_Time desc;";

		return $queryString;
	}
	function getYears(){
		$queryString = 
			"SELECT DISTINCT 
				DATEPART(year, date) AS availableYear  
			FROM mix_produced_activities_view 
			ORDER BY availableYear desc";
		return $queryString;
	}
?>